package com.bawei.live.view

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.util.Log
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bawei.base.RoutePath
import com.bawei.common.base.BaseActivity
import com.bawei.common.entity.SimpleVideoEntity
import com.bawei.image.ImgOptions
import com.bawei.image.LoadImageUtil
import com.bawei.live.R
import com.bawei.live.databinding.ActivityLiveDetailBinding
import com.bawei.live.view.adapter.CommonAdapter
import com.bawei.live.view.adapter.HeadPopoleAdapter
import com.google.android.material.slider.Slider.OnChangeListener
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = RoutePath.PATH_LIVE_DETAIL_PAGE)
class LiveDetailActivity : BaseActivity<ActivityLiveDetailBinding>() {

    @Autowired
    lateinit var videoEntity : SimpleVideoEntity

    lateinit var adapter : HeadPopoleAdapter
    lateinit var commonAdapter : CommonAdapter

    val list = mutableListOf(
        R.drawable.baseline_person_pin_24,
        R.drawable.baseline_person_pin_24,
        R.drawable.baseline_person_pin_24,
        R.drawable.baseline_person_pin_24,
        R.drawable.baseline_person_pin_24,
        R.drawable.baseline_person_pin_24,
        R.drawable.baseline_person_pin_24,
        R.drawable.baseline_person_pin_24,
        R.drawable.baseline_person_pin_24,
        R.drawable.baseline_person_pin_24,
        R.drawable.baseline_person_pin_24
    )

    var currentText : String = ""

    val commonList = mutableListOf<String>(
        "来了",
        "善语结善缘，恶语伤人心！！！",
        "来了"
    )

    override fun getLayoutId(): Int = R.layout.activity_live_detail

    override fun initViews() {
        ARouter.getInstance().inject(this)

        mDataBinding.liveRecList.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)
        adapter = HeadPopoleAdapter(list)
        mDataBinding.liveRecList.adapter = adapter

        mDataBinding.commonLive.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
        commonAdapter = CommonAdapter(commonList)
        mDataBinding.commonLive.adapter = commonAdapter

        mDataBinding.liveGsy.findViewById<View>(com.shuyu.gsyvideoplayer.R.id.back).visibility = View.GONE
        mDataBinding.liveGsy.findViewById<View>(com.shuyu.gsyvideoplayer.R.id.start).visibility = View.GONE
        mDataBinding.liveGsy.findViewById<View>(com.shuyu.gsyvideoplayer.R.id.bottom_progressbar).visibility = View.GONE

//        mDataBinding.liveGsy.findViewById<View>(com.shuyu.gsyvideoplayer.R.id.).visibility = View.GONE
        mDataBinding.liveGsy.setUp(videoEntity.videopath,true,"")
        mDataBinding.liveGsy.isLooping = true
        mDataBinding.liveGsy.startPlayLogic()

        Log.i("YANG", "initViews: " + videoEntity.image_url)
        LoadImageUtil.loadUrl(this,videoEntity.avatar_url,mDataBinding.liveHead, ImgOptions.Builder.isCircle(true).build())

        mDataBinding.textView1.text = videoEntity.name

        mDataBinding.textCommonEt.addTextChangedListener(object :TextWatcher{
            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {

            }

            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
                s.let {
                    currentText = it.toString()
                }
            }

            override fun afterTextChanged(s: Editable?) {

            }

        })

        mDataBinding.sendCommonLive.setOnClickListener {
            commonList.add(0,currentText)
            mDataBinding.textCommonEt.text = null
            commonAdapter.notifyDataSetChanged()
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        mDataBinding.liveGsy.onVideoPause()
        mDataBinding.liveGsy.release()
    }
}